<?php
/*
 * Created on 01/06/2012
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
?>
<fieldset>
    <legend><?php echo __('Teléfonos ')?></legend>
    <ul>
        <?php foreach ($form['CrmContactoTelefono'] as $occurrence):?>
        <li>
            <!-- Añado el id, aunque es un campo oculto para poder realizar borrados -->
            <span class="oculto"><?php echo $occurrence['id'] ?></span>
            <?php echo $occurrence['telefono']->renderError() ?>
            <?php echo $occurrence['telefono'] ?>
            -
            <?php echo $occurrence['tipo']->renderError() ?>
            <?php echo $occurrence['tipo'] ?>

            <?php echo $occurrence['delete']->renderError() ?>
            <?php echo $occurrence['delete'] ?>
            <?php echo $occurrence['delete']->renderLabel() ?>  
        </li>
        <?php endforeach; ?>
    </ul>
</fieldset>
<input type="button" id="addtelefono" href="#" value="<?php echo __('Añadir telefono')?>"/>

<script>
/* web/js/eventform.js */
newfieldscount = 0;

function addNewField(num){
  return $.ajax({
    type: 'GET',
    url: '<?php echo url_for('@crm_contacto')?>'+'/addTelefono?num='+num,
    async: false
  }).responseText;
}

var removeNewT = function(){
  $('.removenewT').click(function(e){
    e.preventDefault();
    $(this).parent().remove();
  })
};

$(document).ready(function(){
  $('#addtelefono').click(function(e){
    e.preventDefault();
    $('#telefonos ul').append(addNewField(newfieldscount));
    newfieldscount = newfieldscount + 1;
    $('.removenew').unbind('click');
    removeNewT();
  });
});

</script>

